<cfcomponent extends="TracRpcAdapterAbstractTest">

	<cffunction name="testGetTicketFields" returntype="void" access="public">
		<cfset var params = structNew()>
		<cfset var response = "" />
		<cfset var results = variables.tracRpcAdapter.runMethod(1,"ticket.getTicketFields",params) />
 		<cfset response = xmlparse(CFML2XMLRPC(results["results"],"response")) />
		<cfset assertComplexValue(value=response) />
	</cffunction>
				
	<cffunction name="testGetTicketIdsQuery" returntype="void" access="public">
		<cfset var params = structNew()>
		<cfset var results = xmlCall("ticket.query",'<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>ticket.query</methodName><params><param><value>order=id&amp;status=new|assigned|reopened</value></param></params></methodCall>') />
		<cfset assertComplexValue(value=results) />
	</cffunction>

	<cffunction name="testGetTicket" returntype="void" access="public">
		<cfset var params = structNew()>
		<cfset var response = "" />
		<cfset var results = "" />
		<cfset params["projectID"] = variables.projectId />
		<cfset params["ticketId"] = "1" />
		<cfset results = variables.tracRpcAdapter.runMethod(1,"ticket.get",params) />
 		<cfset response = xmlparse(CFML2XMLRPC(results["results"],"response")) />
		<cfset assertComplexValue(value=response) />
	</cffunction>

	<cffunction name="testGetTickets" returntype="void" access="public">
		<cfset var params = structNew() />
		<cfset var response = "" />
		<cfset var results = "" />
		<cfset var xmlrequest = "" />
		<cfset var curdir = getDirectoryFromPath(getCurrentTemplatePath()) />
		<cffile action="read" file="#curdir#xmlio/in.ticket.query.xml" variable="xmlrequest" />
		<cfset rpcCall = XMLRPC2CFML(data=xmlrequest) />
		<cfset results = variables.tracRpcAdapter.runMethod(1,rpcCall["method"],rpcCall["params"]) />
 		<cfset response = CFML2XMLRPC(results["results"],"response") />
		<cfset assertComplexValue(value=response) />
	</cffunction>

	<cffunction name="testGetTicketMultiCall" returntype="void" access="public">
		<cfset var params = structNew()>
		<cfset var results = "" />
		<cfset results = multiCall( '<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>system.multicall</methodName><params><param><value><array><data><value><struct><member><name>params</name><value><array><data><value><i4>1</i4></value></data></array></value></member><member><name>methodName</name><value>ticket.get</value></member></struct></value><value><struct><member><name>params</name><value><array><data><value><i4>2</i4></value></data></array></value></member><member><name>methodName</name><value>ticket.get</value></member></struct></value></data></array></value></param></params></methodCall>') />
		<cfset assertComplexValue(value=results) />
	</cffunction>

	<cffunction name="testGetTicketComments" returntype="void" access="public">
		<cfset var results = xmlCall("ticket.changelog",'<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>ticket.changeLog</methodName><params><param><value><i4>1</i4></value></param><param><value><i4>0</i4></value></param></params></methodCall>') />
		<cfset assertComplexValue(value=results) />
	</cffunction>

	<cffunction name="testGetTicketAttachments" returntype="void" access="public">
		<cfset var results = xmlCall("ticket.listAttachments",'<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>ticket.listAttachments</methodName><params><param><value><i4>11</i4></value></param></params></methodCall>') />
		<cfset assertComplexValue(value=results) />
	</cffunction>

	<cffunction name="testGetTicketAttachment" returntype="void" access="public">
		<cfset var results = xmlCall("ticket.getAttachment",'<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>ticket.getAttachment</methodName><params><param><value><i4>1</i4></value></param><param><value>llmsClassIds.csv</value></param></params></methodCall>') />
    <cfset var validResponse = '<?xml version="1.0"  standalone="no"?><methodResponse><params><param><value><base64>IkxMTVNjbGFzc0lEIgoxMjE4NQoxMjE4NAoxMjE4OAoxMjE4OQoxMjE4NgoxMjE4NwoxMjE1NQoxMjE1NgoxMjE1NwoxMjE1OAoxMjE1OQoxMjE2MAoxMjE2MQoxMjE2MgoxMjE2MwoxMjE2NAoxMjE2NQoxMjE2NgoxMjE2NwoxMjE2OAoxMjE2OQoxMjE3MAoxMjE3MQoxMjE3MgoxMjE3MwoxMjE3NAoxMjE3NQoxMjE3NgoxMjE3NwoxMjE3OAoxMjE3OQoxMjE4MAoxMjE4MQoxMjE4MgoxMjE4MwoxMjE1MAoxMjE1MQoxMjE1MgoxMjE1MwoxMjE1NAo=</base64></value></param></params></methodResponse>' />
		<cfset var validXmlResponse = xmlParse(validResponse) />
		<cfset assertEqualsString(expected=toString(validXmlResponse), actual=toString(results), failureMessage="getAttachment: Invalid Response") />
	</cffunction>

	<cffunction name="testGetTicketAvailableActions" returntype="void" access="public">
		<cfset var results = xmlCall("ticket.getAvailableActions",'<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>ticket.getAvailableActions</methodName><params><param><value><i4>1</i4></value></param></params></methodCall>') />
		<cfset assertComplexValue(value=results) />
	</cffunction>

	<cffunction name="testGetRecentChanges" returntype="void" access="public">
		<cfset var results = xmlCall("ticket.getRecentChanges",'<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>ticket.getRecentChanges</methodName><params><param><value><dateTime.iso8601>20080212T10:22:48</dateTime.iso8601></value></param></params></methodCall>') />
		<cfset assertComplexValue(value=results) />
	</cffunction>

 	<cffunction name="testAddAttachment" returntype="void" access="public">
		<cfset var results = xmlCall("ticket.putAttachment",'<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>ticket.putAttachment</methodName><params><param><value><i4>1</i4></value></param><param><value>llmsClassIds.csv</value></param><param><value>I really like cheese</value></param><param><value><base64>IkxMTVNjbGFzc0lEIgoxMjE4NQoxMjE4NAoxMjE4OAoxMjE4OQoxMjE4NgoxMjE4NwoxMjE1NQoxMjE1NgoxMjE1NwoxMjE1OAoxMjE1OQoxMjE2MAoxMjE2MQoxMjE2MgoxMjE2MwoxMjE2NAoxMjE2NQoxMjE2NgoxMjE2NwoxMjE2OAoxMjE2OQoxMjE3MAoxMjE3MQoxMjE3MgoxMjE3MwoxMjE3NAoxMjE3NQoxMjE3NgoxMjE3NwoxMjE3OAoxMjE3OQoxMjE4MAoxMjE4MQoxMjE4MgoxMjE4MwoxMjE1MAoxMjE1MQoxMjE1MgoxMjE1MwoxMjE1NAo=</base64></value></param><param><value><boolean>0</boolean></value></param></params></methodCall>') />
		<cfset assertNotEquals("3",results.XmlRoot.xmlChildren[1].xmlChildren[1].xmlChildren[1].xmlChildren[1].xmlText) />
	</cffunction>

	<cffunction name="testAddComment" returntype="void" access="public">
		<cfset var results = xmlCall("ticket.update",'<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>ticket.update</methodName><params><param><value><i4>1</i4></value></param><param><value>testing comment</value></param><param><value><struct><member><name>summary</name><value>w00t3rz</value></member><member><name>milestone</name><value>milestone1</value></member><member><name>keywords</name><value>sodium oxide</value></member><member><name>component</name><value>component2</value></member><member><name>description</name><value>superfudge</value></member><member><name>priority</name><value>normal</value></member><member><name>owner</name><value>denny</value></member><member><name>severity</name><value>normal</value></member><member><name>type</name><value>defect</value></member><member><name>cc</name><value></value></member><member><name>version</name><value>2.0</value></member></struct></value></param><param><value><boolean>1</boolean></value></param></params></methodCall>') />
		<cfset assertComplexValue(value=results) />
	</cffunction>

	<cffunction name="testUpdateTicket" returntype="void" access="public">
		<cfset var results = xmlCall("ticket.update",'<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>ticket.update</methodName><params><param><value><i4>1</i4></value></param><param><value></value></param><param><value><struct><member><name>summary</name><value>testing</value></member><member><name>milestone</name><value>milestone2</value></member><member><name>keywords</name><value>stanly</value></member><member><name>component</name><value>component1</value></member><member><name>description</name><value>Well now</value></member><member><name>priority</name><value>normal</value></member><member><name>owner</name><value>denny</value></member><member><name>severity</name><value>normal</value></member><member><name>type</name><value>enhancement</value></member><member><name>cc</name><value>dan</value></member><member><name>version</name><value>1.0</value></member></struct></value></param><param><value><boolean>1</boolean></value></param></params></methodCall>') />
		<cfset assertComplexValue(value=results) />
	</cffunction>

	<cffunction name="testCreateTicket" returntype="void" access="public">
		<cfset var results = xmlCall("ticket.create",'<?xml version="1.0" encoding="UTF-8"?><methodCall><methodName>ticket.create</methodName><params><param><value>w00t3rz</value></param><param><value>superfudge</value></param><param><value><struct><member><name>milestone</name><value>milestone1</value></member><member><name>keywords</name><value>sodium oxide</value></member><member><name>component</name><value>component2</value></member><member><name>priority</name><value>normal</value></member><member><name>owner</name><value>denny</value></member><member><name>severity</name><value>normal</value></member><member><name>type</name><value>defect</value></member><member><name>cc</name><value></value></member><member><name>version</name><value>2.0</value></member></struct></value></param><param><value><boolean>1</boolean></value></param></params></methodCall>') />
		<cfset assertComplexValue(value=results) />
	</cffunction>
				
</cfcomponent>